from flask import redirect, request

from blueprints import personal_blueprint
from models import Personal, QueryOneInstance, UpdateInstance
from tools.decorate import pack_session
from tools.response import  Response, ResponsePostJson

def ResponsePostPerssonal(required, data, msg):
    def cb(json):
        UpdateInstance(QueryOneInstance(Personal, {'uid': data['session']['uid']}), json)
        return Response(msg)
    return ResponsePostJson(required, cb)

@personal_blueprint.route('/my/model/personal/intro', methods=['POST'])
@pack_session
def post_my_model_of_personal_intro(data):
    return ResponsePostPerssonal(['intro'], data, "个人介绍更新成功")

@personal_blueprint.route('/my/model/personal/role', methods=['POST'])
@pack_session
def post_my_model_of_personal_role(data):
    return ResponsePostPerssonal(['role'], data, "角色信息更新成功")

@personal_blueprint.route('/my/model/personal/img_icon', methods=['POST'])
@pack_session
def post_my_model_of_personal_img_icon(data):
    return ResponsePostPerssonal(['img_icon'], data, "头像更新成功")

@personal_blueprint.route('/my/model/personal/img_background', methods=['POST'])
@pack_session
def post_my_model_of_personal_img_background(data):
    return ResponsePostPerssonal(['img_background'], data, "背景图片更新成功")
